<template>
  <div>
    <header>
      <van-icon name="arrow-left" @click="handleBack()" size="25"/>
      <span>地址管理</span>
    </header>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      :disabled-list="disabledList"
      disabled-text="以下地址超出配送范围"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
import { ref } from 'vue';
import { Toast } from 'vant';
import 'vant/es/toast/style';
import { useRouter } from 'vue-router';
import useUserStore from '../../store/user';
export default {
  setup() {
    const chosenAddressId = ref('1');
    const store = useUserStore();
    const list = store.address;
    const disabledList = [
      {
        id: '3',
        name: '王五',
        tel: '1320000000',
        address: '浙江省杭州市滨江区江南大道 15 号',
      },
    ];
    const router = useRouter()
    const onAdd = () => router.push('/newaddress')
    const onEdit = (item, index) => Toast('编辑地址:' + index);

    return {
      list,
      onAdd,
      onEdit,
      disabledList,
      chosenAddressId,
    };
  },
  methods: {
      handleBack() {
        this.$router.back()
      },
    },
}
</script>

<style lang="less" scoped>
  header{
    height: 44px;
    font-size: 16px;
    line-height: 44px;
    display: flex;
    justify-content: left;
    align-items: center;
    padding: 5px;
  }
</style>
